/*=====================================================
Critical Links
Auto Configuration Server

Authors:
	Rui Eduardo Gouveia Gil - r-gil@critical-links.com

Date: 2010
Version 0.1
=======================================================*/
#include "data/Configuration.h"
#include "database/DataBase.h"
#include "ACSConfig.h"

namespace acs
{

Configuration::Configuration()
{

}

Configuration::~Configuration()
{

}

void Configuration::setID(const int id)
{
	this->id = id;
}

int Configuration::getID() const
{
	return this->id;
}

void Configuration::setRWan(const bool rwan)
{
	this->rwan = rwan;
}

bool Configuration::isRWan() const
{
	return this->rwan;
}

void Configuration::setRUsers(const bool rusers)
{
	this->rusers = rusers;
}

bool Configuration::isRUsers() const
{
	return this->rusers;
}

void Configuration::setUpdated(time_t updated)
{
	this->updated = updated;
}

time_t Configuration::getUpdated() const
{
	return this->updated;
}

void Configuration::setCreation(time_t creation)
{
	this->creation = creation;
}

time_t Configuration::getCreation() const
{
	return this->creation;
}

void Configuration::setName(const std::string& name)
{
	this->name = name;
}

std::string Configuration::getName() const
{
	return this->name;
}

void Configuration::setDescription(const std::string& description)
{
	this->description = description;
}

std::string Configuration::getDescription() const
{
	return this->description;
}

void Configuration::setConfigFileName(const std::string& configFileName)
{
	this->configFileName = configFileName;
}

std::string Configuration::getConfigFileName() const
{
	return this->configFileName;
}

void Configuration::setCommands(const std::vector<Command>& commands)
{
	this->commands = commands;
}

std::vector<Command> Configuration::getCommands() const
{
	return this->commands;
}

void Configuration::setSHA(const std::string& sha)
{
	this->sha = sha;
}

std::string Configuration::getSHA() const
{
	return sha;
}

void Configuration::setCFType(const std::string& cfType)
{
	this->cfType = cfType;
}

std::string Configuration::getCFType() const
{
	return this->cfType;
}

void Configuration::setCFReboot(const std::string& cfReboot)
{
	this->cfReboot = cfReboot;
}

std::string Configuration::getCFReboot() const
{
	return this->cfReboot;
}

void Configuration::setCFRelease(const std::string& cfRelease)
{
	this->cfRelease = cfRelease;
}

std::string Configuration::getCFRelease() const
{
	return this->cfRelease;
}

void Configuration::setCFCreation(const std::string& cfCreation)
{
	this->cfCreation = cfCreation;
}

std::string Configuration::getCFCreation() const
{
	return this->cfCreation;
}

void Configuration::setCFLicenseID(const std::string& cfLicenseID)
{
	this->cfLicenseID = cfLicenseID;
}

std::string Configuration::getCFLicenseID() const
{
	return this->cfLicenseID;
}

void Configuration::setCFVoipSounds(const std::string& cfVoipSounds)
{
	this->cfVoipSounds = cfVoipSounds;
}

std::string Configuration::getCFVoipSounds() const
{
	return this->cfVoipSounds;
}

void Configuration::setCFDescription(const std::string& cfDescription)
{
	this->cfDescription = cfDescription;
}

std::string Configuration::getCFDescription() const
{
	return this->cfDescription;
}

std::string Configuration::toXML() const
{
	std::stringstream stream;

	stream << "<Configuration>";
	stream << "<ID>" <<  this->id << "</ID>";
	stream << "<RWan>" <<  this->rwan << "</RWan>";
	stream << "<RUsers>" <<  this->rusers << "</RUsers>";
	stream << "<Updated>" <<  this->updated << "</Updated>";
	stream << "<Creation>" <<  this->creation << "</Creation>";
	stream << "<UpdatedStr>" <<  rgcpp::ToString(this->updated,"%Y-%m-%d %X") << "</UpdatedStr>";
	stream << "<CreationStr>" <<  rgcpp::ToString(this->creation,"%Y-%m-%d %X") << "</CreationStr>";
	stream << "<Name>" <<  this->name << "</Name>";
	stream << "<Description>" <<  this->description << "</Description>";
	stream << "<ConfigFileName>" <<  this->configFileName << "</ConfigFileName>";
	stream << "<DeviceCount>" <<  DataBase::getInstance()->getConfigurationDevicesCount(this->id) << "</DeviceCount>";
	stream << "</Configuration>";

	return stream.str();
}

std::string Configuration::toXMLFull() const
{
	std::stringstream stream;

	stream << "<Configuration>";
	stream << "<ID>" <<  this->id << "</ID>";
	stream << "<RWan>" <<  this->rwan << "</RWan>";
	stream << "<RUsers>" <<  this->rusers << "</RUsers>";
	stream << "<Updated>" <<  this->updated << "</Updated>";
	stream << "<Creation>" <<  this->creation << "</Creation>";
	stream << "<UpdatedStr>" <<  rgcpp::ToString(this->updated,"%Y-%m-%d %X") << "</UpdatedStr>";
	stream << "<CreationStr>" <<  rgcpp::ToString(this->creation,"%Y-%m-%d %X") << "</CreationStr>";
	stream << "<Name>" <<  this->name << "</Name>";
	stream << "<Description>" <<  this->description << "</Description>";
	stream << "<ConfigFileName>" <<  this->configFileName << "</ConfigFileName>";
	stream << "<DeviceCount>" <<  DataBase::getInstance()->getConfigurationDevicesCount(this->id) << "</DeviceCount>";

	stream << "<CFType>" <<  this->cfType << "</CFType>";
	if(!this->configFileName.empty() && boost::filesystem::exists(ACSConfig::getDataDirectory()+std::string("Configuration_BackupRestore_")+rgcpp::ToString(this->id)))
		stream << "<CFSize>" <<  rgcpp::ToStringHumanReadable(boost::filesystem::file_size(ACSConfig::getDataDirectory()+std::string("Configuration_BackupRestore_")+rgcpp::ToString(this->id))) << "</CFSize>";
	else
		stream << "<CFSize></CFSize>";
	stream << "<CFReboot>" <<  this->cfReboot << "</CFReboot>";
	stream << "<CFRelease>" <<  this->cfRelease << "</CFRelease>";
	stream << "<CFCreation>" <<  this->cfCreation << "</CFCreation>";
	stream << "<CFLicenseID>" <<  this->cfLicenseID << "</CFLicenseID>";
	stream << "<CFVoipSounds>" <<  this->cfVoipSounds << "</CFVoipSounds>";
	stream << "<CFDescription>" <<  this->cfDescription << "</CFDescription>";
	stream << "</Configuration>";

	return stream.str();
}

}
